﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using DAL;
using Models;
using WebShopAPI.Models;
namespace WebShopAPI.Controllers
{
    public class sp_consigneeController : ApiController
    {
        public ResponData get(int userid)
        {
            sp_consigneeDAL pc = new sp_consigneeDAL();
            List<sp_consignee> cc = pc.getall().Where(p => p.user_id == userid).ToList();
            for (int i = 0; i < cc.Count; i++)
            {
                string vv = cc[i].cgn_tel.Substring(0, 3) + "****" + cc[i].cgn_tel.Substring(6, 4);
                cc[i].cgn_tel = vv;
            }
            ResponData rs = new ResponData();
            rs.data = cc;
            rs.meta.status = 200;
            rs.meta.msg = "查询成功";
            return rs;
        }
        public ResponData delete(int id)
        {
            sp_consigneeDAL d = new sp_consigneeDAL();
            int v = d.delconsi(id);
            ResponData da = new ResponData();
            da.data = v;
            da.meta.status = 200;
            da.meta.msg = "删除成功";
            return da;
        }
        public ResponData post(int userid, cin c)
        {
            sp_consignee s = new sp_consignee();
            s.user_id = userid;
            s.cgn_name = c.name;
            s.cgn_address = c.dz;
            s.cgn_tel = c.mobile;
            s.cgn_code = "123";
            s.delete_time = null;
            sp_consigneeDAL pc = new sp_consigneeDAL();
            int x = pc.addconsi(s);
            ResponData da = new ResponData();
            da.data = x;
            da.meta.status = 200;
            da.meta.msg = "添加成功";
            return da;
        }
    }
    public class cin
    {
        public string dz { get; set; }
        public string name { get; set; }
        public string mobile { get; set; }
    }
}
